package spil;

import boundaryToMatador.GUI;
import java.util.*;

public class Game {
	static Dice d1 = new Dice();
	static Scanner in = new Scanner(System.in);
	
	public static void main(String[] args) {
		Player p1 = new Player(1);
		Player p2 = new Player(2);
		do {
			playerTurn(p1);
			if(p1.hasWon())
				break;
			playerTurn(p2);
		} while(!p2.hasWon());
		if(p1.hasWon())
			System.out.println(p1 + " has won");
		else if(p2.hasWon())
			System.out.println(p2 + " has won");
	}

	public static void playerTurn(Player p) {		//spiller turen
		do {
			System.out.println(p + "'s turn\nType anything to roll");
			in.next();
			d1.roll();
			p.move(d1.getSum());
			if(p.getFelt() != 9)					//stopper extraturen hvis man ikke lander på Werewall
				p.loseTurn();
			System.out.println(felt(p));
			System.out.println(p + " has " + p.konto + " points.\n");
			GUI.setDice(d1.getd1(), d1.getd2());		//sætter terningernes værdi på GUI'en
			if(p.konto.getBalance() >= 3000)
				p.win();
		} while(p.extraTurn());
	}
	
	public static String felt(Player p) {
		switch(p.getFelt()) {
		case 1: p.konto.insert(250);
			return "Tower: +250";
		case 2: p.konto.withdraw(200);
			return "Crater: -200";
		case 3: p.konto.withdraw(100);
			return "Palace: -100";
		case 4: p.konto.withdraw(20);
			return "Cold Desert: -20";
		case 5: p.konto.insert(0);
			return "Walled City: +180";
		case 6:return "Monastery: 0";
		case 7: p.konto.withdraw(70);
			return "Black Cave: -70";
		case 8: p.konto.withdraw(60);
			return "Huts in the mountain: -60";
		case 9: p.secondTurn();			//giver extratur på Werewall
			p.konto.withdraw(80);
			return "The Werewall (werewolf-wall): -80, extra turn";
		case 10: p.konto.withdraw(90);
			return "The pit: -90";
		case 11: p.konto.insert(650);
			return "Goldmine: +650";
		default: return "Fejl";
		}
	}
}
